package com.zyn.inventory.management.services;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.zyn.inventory.management.dao.RoleDao;
import com.zyn.inventory.management.entities.Role;

@Transactional( propagation = Propagation.REQUIRED )
@Service
public class RoleServiceImpl extends EntityServiceImpl<Role, RoleDao> implements RoleService {
    
    public Role getRoleByAuthority(String authority) {
        Role role = entityDao.getByAuthority(authority);
        if(role == null) {
            role = new Role();
            role.setAuthority(authority);
            entityDao.add(role);
        }
        return role;
    }
    
    @Resource
	public void setEntityDao(RoleDao entityDao) {
    	this.entityDao = entityDao;
	}
}
